#include<iostream>
#include<cstring>
#include<unistd.h>
#include<pthread.h>

__thread int cnt = 1;//__thread关键字会该变量在线程的局部存储开辟一份,每个线程的cnt只有自己能看到

void* routine(void* args)
{
    int t = 10;
    while(t--)
    {
        sleep(1);
        std::cout << "我是线程: " << cnt++ << std::endl; 
        
    }
    return nullptr;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,nullptr,routine,(void*)"hhh");
    while(true)
    {
        std::cout << "我是主线程: " << cnt << std::endl;
        sleep(2);
    }
    std::cout << cnt << std::endl;
    return 0;
}